package com.yeda.engine.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/***
 *
 * @author Administrator
 */
public class QuartzCronDateUtils {
    /***
     *  日期转换cron表达式时间格式
     * @param localDateTime
     * @param dateFormat
     * @return
     */
    public static String formatDateByPattern(LocalDateTime localDateTime, String dateFormat) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat);
        String formatTimeStr = null;
        if (localDateTime != null) {
            formatTimeStr = localDateTime.format(dateTimeFormatter);
        }
        return formatTimeStr;
    }

    /*** 
     * convert Date to cron 
     * @param localDateTime:时间
     * @return
     */
    public static String getCron(LocalDateTime localDateTime) {
        String dateFormat = "ss mm HH dd MM ? yyyy";
        return formatDateByPattern(localDateTime, dateFormat);
    }
}